home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 2000 November: Tool Chest / Dev.CD Nov 00 TC Disk 1.toast / Sample Code / Games / SprocketInvaders / Source / NetSprocketSupport.h < prev    next >
Encoding:
Text File  |  2000-09-28  |  2.7 KB  |  119 lines  |  [TEXT/CWIE]

  1. //•    ------------------------------------------------------------------------------------------    •
  2. //•
  3. //•    Copyright © 1996 Apple Computer, Inc., All Rights Reserved
  4. //•
  5. //•
  6. //•        You may incorporate this sample code into your applications without
  7. //•        restriction, though the sample code has been provided "AS IS" and the
  8. //•        responsibility for its operation is 100% yours.  However, what you are
  9. //•        not permitted to do is to redistribute the source as "DSC Sample Code"
  10. //•        after having made changes. If you're going to re-distribute the source,
  11. //•        we require that you make it clear in the source that the code was
  12. //•        descended from Apple Sample Code, but that you've made changes.
  13. //•
  14. //•        Authors:
  15. //•            Jamie Osborne
  16. //•
  17. //•    ------------------------------------------------------------------------------------------    •
  18.  
  19. #ifndef __NETSPROCKETSUPPORT__
  20. #define __NETSPROCKETSUPPORT__
  21.  
  22. //•    ------------------------------    Includes
  23.  
  24. #include <NetSprocket.h>
  25.  
  26. //•    ------------------------------    Public Definitions
  27. //•    ------------------------------    Public Types
  28.  
  29. typedef struct WelcomeMessage
  30. {
  31.     NSpMessageHeader    h;
  32.     UInt32                gameID;
  33. } WelcomeMessage;
  34.  
  35. typedef struct ChatTextMessage
  36. {
  37.     NSpMessageHeader    h;
  38.     Str255                text;
  39. } ChatTextMessage;
  40.  
  41. typedef struct StartGameMessage
  42. {
  43.     NSpMessageHeader    h;
  44.     SInt32                seed;
  45. } StartGameMessage;
  46.  
  47. typedef struct PlayerInputMessage
  48. {
  49.     NSpMessageHeader    h;
  50.     Boolean                left;
  51.     Boolean                right;
  52.     Boolean                fire;
  53. } PlayerInputMessage;
  54.  
  55. //    Constants used for NetSprocket
  56. enum
  57. {
  58.     kStandardMessageSize = 500,
  59.     kBufferSize = 100000,
  60.     kQElements = 40,
  61.     kGameID = 'Invd',
  62.     kTimeout = 5000,
  63.     kMaxPlayers = 2
  64. };
  65.  
  66. typedef enum
  67. {
  68.         kSlacking,
  69.         kHosting,
  70.         kJoining,
  71.         kWaiting,
  72.         kStarting,
  73.         kRunning,
  74.         kDenoument
  75. } NetworkState;
  76.  
  77. enum
  78. {
  79.     kChatTextMessage = 10000,
  80.     kStartGameMessage = 10001,
  81.     kInputMessage = 10002,
  82.     kEndGameMessage = 10003
  83. };
  84.  
  85. //•    ------------------------------    Public Variables
  86.  
  87. extern NSpGameReference gNetGame;
  88. extern Boolean gIAmHost;
  89. extern NetworkState gNetState;
  90. extern Boolean gGotEndGameMessage;
  91. extern Boolean gNetSprocketPresent;
  92. extern Boolean gReceivedInput;
  93.  
  94. extern Str31 kNetworkGameName;
  95. extern Str31 kJoinDialogLabel;
  96. extern Str31 kNBPType;        // This should be the same as kGameID
  97.  
  98. //•    ------------------------------    Public Functions
  99.  
  100. #ifdef __cplusplus
  101. extern "C" {
  102. #endif
  103.  
  104. extern Boolean InitNetworking(void);
  105. extern Boolean NetSprocketPresent(void);
  106. extern Boolean DoHostGame(void);
  107. extern Boolean DoJoinGame(void);
  108. extern void ShutdownNetworking(void);
  109. extern void HandleNetworking(void);
  110. extern void SendInputState(Boolean left, Boolean right, Boolean fire);
  111. extern void SendEndGame();
  112. extern Boolean WaitForAllPlayers(void);
  113. extern void SendStartGame(void);
  114.  
  115. #ifdef __cplusplus
  116. }
  117. #endif
  118.  
  119. #endif